  <form action="<?php echo $PHP_SELF; ?>" method="POST">

	<h3>Setlist</h3>
    <input type="hidden" name="event_id" value="<?php echo $c->event->id; ?>"/>
    <input type="hidden" id="setlistIds" name="setlistIds" value="<?php echo $c->setlistIds; ?>" />


<!-- yeah, it's invalid XHTML.  Suck it up, pedant-boy :) -->
<div id="searchshow" <?php if (count($c->setlistSongs) == 0) echo "style=\"display:none;\""; ?>>
<a href="#" onclick="javascript:toggleVisibility('search');">Show Songs to Add</a>
</div>
<div id="search" style="float:left;<?php if (count($c->setlistSongs) > 0) echo "display:none;"; ?>">
	<a href="#" onclick="javascript:toggleVisibility('search');">Hide Songs to Add</a><br/>
	  <select name="newSongs[]" size="30" multiple >
	    <?php foreach ($c->songs as $song) { ?>
	    	<option value="<?php echo $song->id; ?>"><?php echo $song->title; ?></option>
	    <?php } ?>
	  </select></br>
	  <input type="submit" name="action" value="Add To Setlist" />
</div>

<table>
  <tr>
    <td valign="top" width="400px">
		<ul id="setlist" class="boxy">
		        <?php foreach ($c->setlistSongs as $setlistSong) { ?>
		        	<li itemID="<?php echo $setlistSong->setlist->id . "-" . $setlistSong->song->id; ?>"><table width="100%" cellspacing=0 cellpadding0 border=0><tr>
		        		<td><?php echo HtmlUtil::internalLink("[-]", "setlist", $userRoles, array("action" => "remove", "event_id" => $c->event->id, "id" => $setlistSong->setlist->id)); ?>
		        			<?php echo $setlistSong->song->title; ?></td>
		        		<td align="right"><input type="text" onclick="this.focus();" size="20" name="notes[<?php echo $setlistSong->setlist->id; ?>]" value="<?php echo $setlistSong->setlist->note; ?>" /></td>
		        	</tr></table></li>
		        <?php } ?>
		</ul>
	</td>
  </tr>
  <tr>
    <td><input type="submit" name="action" value="Save" onclick="saveList('setlist', 'setlistIds')"/></td>
  </tr>
</table>


  </form>

<script language="JavaScript" type="text/javascript"><!--
        var dragsort = ToolMan.dragsort()
        var junkdrawer = ToolMan.junkdrawer()

        window.onload = function() {
                dragsort.makeListSortable(document.getElementById("setlist"),
                                verticalOnly, saveOrder)

        }

        function verticalOnly(item) {
                item.toolManDragGroup.verticalOnly()
        }

        function saveOrder(item) {
                var group = item.toolManDragGroup
                var list = group.element.parentNode
                var id = list.getAttribute("id")
                if (id == null) return
                group.register('dragend', function() {
                        ToolMan.cookies().set("list-" + id,
                                        junkdrawer.serializeList(list), 365)
                })
        }

        function saveList(listName, valToChange) {
                var list = document.getElementById(listName);
                var serializedList = junkdrawer.serializeList(list)

				var hidden = document.getElementById(valToChange);
				hidden.value = serializedList;
				return true;
        }

        //-->
</script>
